﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace GameForm.Gamelib
{
    public class TaskBase
    {

        public GameApi api { set; get; }

        public async Task<bool> RunTask(TaskRunInfo taskRunInfo)
        {
            //await api.Action_点击活动任务("抓鬼");

            while (taskRunInfo.IsRun)
            {
                if (api.Dlg_主界面_IsOpen())
                    await OnMainGame();
                else if (api.Dlg_战斗中_IsOpen())
                    await OnKillIng();
                else
                    await OnOther();
                await Task.Delay(1000);
            }
            return true;
        }

        protected virtual async Task<bool> OnOther()
        {
            if (await api.Action_购买摆摊任务物品())
                return true;
            else if (await api.Action_购买商会物品())
                return true;
            else if (await api.Action_购买Npc物品())
                return true;
            else if (await api.Action_上交物品())
                return true;
            else if (await api.Action_工坊摆摊购买物品())
                return true;
            else if (await api.Action_关闭杂框())
                return true;
            return false;
        }

        protected virtual async Task<bool> OnMainGame()
        {
            if (await api.Action_Npc对话())
                return true;
            else
                return await api.Action_点击任务();
        }

        /// <summary>
        /// 战斗中
        /// </summary>
        /// <returns></returns>
        protected virtual Task<bool> OnKillIng()
        {
            return api.Wait_战斗中();
        }
    }
}
